import { del, get, post } from "@/utils/request";


interface PCommonPlan {
    id?: number;          // 可选字段
    uid?: number;         // 可选字段
    title?: string;       // 可选字段
    updateTime?: string;  // 可选字段
    priority?: number;    // 可选字段
    status?: number;      // 可选字段
    type?: TaskType;      // 可选字段
}
const enum TaskType {
    STUDY = 0,
    WORK = 1,
    LIFE = 2,
}

// 新增
const commonPlanAdd = async (plan: PCommonPlan) => {
    try {
        return await post<any>("/commonPlan/add", plan)
    } catch (error) {
        console.error("普通计划新增操作出现问题: ", error);
    }
}
const commonPlanList = async (type: number, status: number) => {
    try {
        const res = await get<PCommonPlan[]>(`/commonPlan/list/${type}/${status}`)
        return res;
    } catch (error) {
        console.error("普通计划查询操作出现问题: ", error);
    }
}
// 修改
const commonPlanUpdate = async (plan: PCommonPlan) => {
    try {
        const res = await post<any>("/commonPlan/update", plan)
        return res;
    } catch (error) {
        console.error("普通计划修改操作出现问题: ", error);
    }
}

// 修改状态
const commonPlanUpdateStatus = async (id: number) => {
    try {
        return await post<any>("/commonPlan/setStatus/" + id)
    } catch (error) {
        console.error("普通计划修改状态操作出现问题: ", error);
    }
}

// 删除
const commonPlanDelete = async (id: number) => {
    try {
        return await del<any>("/commonPlan/delete/" + id)
    } catch (error) {
        console.error("普通计划删除操作出现问题: ", error);
    }
}
// 查询每日待办
interface CommonPlanCount{
    studyCount: number;
    workCount: number;
    lifeCount: number;
}
const commonPlanCount = async () => {
    try {
        return await get<CommonPlanCount>("/commonPlan/count")
    }catch (error) {
        console.error("普通计划每日待办查询操作出现问题: ", error);
    }
}

export {
    commonPlanAdd,
    commonPlanDelete,
    commonPlanUpdateStatus,
    commonPlanUpdate,
    commonPlanList,
    commonPlanCount
}